package com.sgb.capital.view.pop;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.widget.TextView;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.view.WheelView;
import com.sgb.capital.R;
import com.sgb.capital.callback.Constants;
import com.sgb.capital.utils.Utils;

import java.util.ArrayList;
import java.util.List;

import razerdp.basepopup.BasePopupWindow;
import razerdp.util.animation.AnimationHelper;
import razerdp.util.animation.Direction;
import razerdp.util.animation.TranslationConfig;

/**
 * 作者:张磊
 * 日期:2021/4/16 0016
 * 说明:发票
 */
public class InvoicePop extends BasePopupWindow {


    public String mTip = "发票类型错误";
    public List<String> mList;
    private WheelView mWheelView;
    private TextView mTvTitleTip;
    public int mIndex;

    public InvoicePop(Context context) {
        super(context);
    }

    @Override
    public View onCreateContentView() {
        View v = createPopupById(R.layout.cut_pop);
        mTvTitleTip = v.findViewById(R.id.tv_title_tip);
        mWheelView = v.findViewById(R.id.wv);
        v.findViewById(R.id.tv_cancel).setOnClickListener(v1 -> dismiss());
        mList = new ArrayList<>();
        mList.add("发票类型错误");
        mList.add("发票信息错误");
        mList.add("其他");
        mWheelView.setCurrentItem(0);
        mWheelView.setCyclic(false);
        mWheelView.setAdapter(new ArrayWheelAdapter(mList));

        mWheelView.setOnItemSelectedListener(index -> {
            mIndex = index;
            mTip = mList.get(index);
        });
        TextView tv_sure = v.findViewById(R.id.tv_sure);
        tv_sure.setOnClickListener(v1 -> {
            dismiss();
            Utils.sendMsg(Constants.EVENT_SELECT, mTip);
        });
        return v;
    }

    @Override
    protected Animation onCreateShowAnimation() {
        return AnimationHelper.asAnimation()
                .withTranslation(new TranslationConfig()
                        .from(Direction.BOTTOM))
                .toShow();
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return AnimationHelper.asAnimation()
                .withTranslation(new TranslationConfig()
                        .to(Direction.BOTTOM))
                .toDismiss();
    }


    public void show(int index, String title, View view) {
        mTvTitleTip.setText(title);
        mWheelView.setCurrentItem(index);
        setPopupGravity(Gravity.TOP);
        showPopupWindow(view);
    }

    public void show(int index, String title, View view, List<String> datas) {
        mWheelView.setCurrentItem(0);
        mWheelView.setCyclic(false);
        mTip = datas.get(mIndex);
        mWheelView.setAdapter(new ArrayWheelAdapter(mList));
        mWheelView.setAdapter(new ArrayWheelAdapter(datas));
        mTvTitleTip.setText(title);
        mWheelView.setCurrentItem(index);
        setPopupGravity(Gravity.TOP);
        showPopupWindow(view);
    }
}